package logic

import (
	"context"
	"everyone/C/rpc_C/everyone"
	"everyone/C/rpc_C/internal/svc"
	"everyone/C/rpc_C/model/mysql"
	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsInfoLogic {
	return &GoodsInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsInfoLogic) GoodsInfo(in *everyone.GoodsInfoRequest) (*everyone.GoodsItem, error) {
	// todo: add your logic here and delete this line
	g := mysql.Goods{}
	err := g.InFo(in.GoodsId)
	if err != nil {
		logx.Error("商品详情获取失败")
	}

	return &everyone.GoodsItem{
		GoodsId:    int64(g.ID),
		GoodsTitle: g.GoodsTitle,
		GoodsImage: g.GoodsImage,
		GoodsNum:   g.GoodsNum,
		GoodsPrice: float32(g.GoodsPrice),
		GoodsLike:  g.GoodsLike,
	}, nil
}
